import QtQuick

import "../as_qml"

Window {
    id: createRecognizerWin
    width: 640
    height: 480
    visible: true
    title: qsTr("生成识别器模型")

    property color mTextColor: "#1a1c1e"

    function setTipsShow(flag, text) {
        tipsText.color = (flag === true) ? "green" : "red"
        tipsText.text = qsTr(text)
    }

    Connections {
        target: myHandle

        function onCsvFileDirectoryOpened(filePath) {
            openFileText.text = filePath
        }

        function onRecognizerDirectoryOpened(filePath) {
            saveFileText.text = filePath + "/"
        }
    }

    Column {
        id: recognizerSetting
        width: parent.width
        anchors.top: parent.top
        anchors.bottom: tipsBottomRect.bottom
        padding: 4
        spacing: 4

        Row {
            width: parent.width - parent.padding * 4
            height: 28
            spacing: 4

            AsText {
                id: openFileTitleText
                width: 50
                height: parent.height
                text: qsTr("CSV路径:")
                verticalAlignment: Text.AlignVCenter
            }

            AsTextField {
                id: openFileText
                width: parent.width - openFileTitleText.width - openFileBtn.width
                height: parent.height
                placeholderText: qsTr("请选择需要打开的CSV文件")
                color: mTextColor
                readOnly: true
                verticalAlignment: Text.AlignVCenter
            }

            AsButton {
                id: openFileBtn
                width: 80
                height: parent.height
                text: qsTr("选择路径")

                onClicked: {
                    var ret = myHandle.openCSVFile()
                    setTipsShow(ret, (ret === false) ? "操作取消" : "无")
                }
            }
        }

        Row {
            width: parent.width - parent.padding * 4
            height: 28
            spacing: 4

            AsText {
                id: saveFileTitleText
                width: 50
                height: parent.height
                text: qsTr("保存路径:")
                verticalAlignment: Text.AlignVCenter
            }

            AsTextField {
                id: saveFileText
                width: parent.width - saveFileTitleText.width - openFileBtn2.width
                height: parent.height
                placeholderText: qsTr("请选择保存识别器模型文件的路径")
                color: mTextColor
                readOnly: true
                verticalAlignment: Text.AlignVCenter
            }

            AsButton {
                id: openFileBtn2
                width: 80
                height: parent.height
                text: qsTr("选择路径")

                onClicked: {
                    var ret = myHandle.openRecognizerFileDir()
                    setTipsShow(ret, (ret === false) ? "操作取消" : "无")
                }
            }
        }

        Row {
            width: parent.width - parent.padding * 5
            height: 28
            spacing: 4

            AsText {
                id: modeTitleText
                width: 50
                height: parent.height
                text: qsTr("选择模型:")
                verticalAlignment: Text.AlignVCenter
            }

            AsComboBox {
                id: modeComboBox
                width: 80
                height: parent.height
                model: ["Eigen", "Fisher", "LBPH"]
            }

            AsTextField {
                id: xmlFileNameText
                width: parent.width - modeTitleText.width - modeComboBox.width - modeCreateBtn.width
                height: parent.height
                placeholderText: qsTr("输入识别器模型文件名称(不含.xml)")
                color: mTextColor
                verticalAlignment: Text.AlignVCenter
            }

            AsButton {
                id: modeCreateBtn
                width: 80
                height: parent.height
                text: qsTr("生成模型")

                onClicked: {
                    var ret = myHandle.saveRecognizerFile(openFileText.text, saveFileText.text, xmlFileNameText.text, modeComboBox.currentIndex)
                    setTipsShow(ret, (ret === false) ? "生成模型失败,请检查是否选择CSV文件,是否选择保存路径,是否给文件命名" : "无")
                }
            }

        }
    }

    Rectangle {
        id: tipsBottomRect
        width: parent.width
        height: 28
        anchors.bottom: parent.bottom
        color: "#e0e0e0"

        Row {
            anchors.fill: parent

            AsText {
                id: tipsTitle
                width: 40
                height: parent.height
                text: qsTr("提示:")
                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignHCenter
            }

            AsText {
                id: tipsText
                width: parent.width - tipsTitle.width
                height: parent.height
                text: qsTr("无")
                color: "green"
                verticalAlignment: Text.AlignVCenter
            }
        }
    }
}
